<?php

namespace App\Exceptions;

use AlibabaCloud\Client\Request\Request;
use Exception;

class InvalidRequestException extends Exception
{
    //400 404 401 403
    public function __construct($message = '', $code = 400)
    {
        //重写父类构造方法，同时为了保证父类构造方法能够执行需要再次调用父类构造方法
        parent::__construct($message, $code);

    }

    public function render(Request $request)
    {
        if ($request->expectsJson()) {
            return response()->json(['message'=>$this->message],$this->code);
        }
        return view('errors.exception',['message'=>$this->message]);
    }
}
